<?php

// 提交私人定制表单
// POST self.form

namespace app\api\resource\self;
use think\Db;
use think\facade\Session;

class Form
{
    // 方法
    public $_method = ['POST'];
    // 前置
    public $_pre    = ['member'];
    // 描述
    public $_description = '提交私人定制表单';
    // 参数
    public $_param  = [
        'f_mobile'  => '联系手机',
        'f_wechat'  => '联系微信,可选',
        'f_content' => '定制描述',
    ];

    public function run(&$request)
    {
        $params = $request->param();

        if ( empty($params['f_mobile']) )  return [422,'联系手机必须'];
        if ( empty($params['f_content']) ) return [422,'定制描述必须'];

        $member = Session::get('member');

        $data['mid']         = $member['id'];
        $data['mobile']      = $member['mobile'];
        $data['f_mobile']    = $params['f_mobile'];
        $data['f_wechat']    = isset($params['f_wechat']) ? $params['f_wechat'] : '';
        $data['f_content']   = $params['f_content'];
        $data['status']      = 0;
        $data['create_time'] = time();
        $data['update_time'] = 0;
        $data['delete_time'] = 0;
        $num = Db::name('self_form')->insert($data);

        return ($num > 0) ? [201,'提交成功'] : [500,'提交失败'];
    }
}
